<template>
	<view>
		<wyb-popup ref="contactTel" type="bottom" height="350"  radius="6" :showCloseIcon="true"
			title="测试登录">
			<view class="wrapper">
				<view class="title1">授权信息</view>
				<view class="title2">尊敬的用户,小程序需要您的授权才能更好为您服务哦!</view>
				<button class="btn" open-type="getPhoneNumber" @getphonenumber="onGetPhoneNum" @error="onAuthError"
					hover-class="none" scope="phoneNumber" @click="authorizedLogin">
					授权登录
				</button>
			</view>
		</wyb-popup>
	</view>
</template>

<script>
	import {
		saveUserId,
		saveZWZUserDetail,
		delGlobalData
	} from '@/utils';
	export default {
		props: {

		},
		data() {
			return {


			}
		},
		components: {},
		onLoad(e) {

		},
		mounted() {

		},
		created() {},
		onReachBottom() {
			console.log('下拉到底了');
		},
		methods: {
			authorizedLogin(){
				this.$refs.contactTel.close();
			},
			toLogin() {
				this.$refs.contactTel.show();
			},
			onGetPhoneNum(e) {
				if (e.detail.errMsg === 'getPhoneNumber:ok') {
					let encryptedData = {}
					encryptedData['response'] = e.detail.encryptedData
					//把手机号信息传给后台解密
					console.log('要获取手机号了哦',e);
					this.phoneJiemi(JSON.stringify(encryptedData))
				} else {
					uni.showToast({
						title: "授权失败",
						icon: "none"
					});
				}
			},
			//用户拒绝
			onAuthError() {
				uni.showToast({
					icon: "none",
					title: "用户拒绝授权，授权失败",
				})
			},
			phoneJiemi(encryptedData) {
				this.$request(
					"member/mall/aliPay/user/bindThirdMobile", {
						content: encryptedData,
						uid:this.$getUid()
					},
					"post",
					true
				).then((res) => {
					if (res.businessSuccess || res.success) {
						let userDetail = (res && res.data) || {}
						let uid = userDetail.uid
						console.log('名字不是手机号吗',userDetail);
						saveUserId(uid)
						saveZWZUserDetail(userDetail)
						this.$emit('noticeRefresh');
					} else {
						var that = this
						uni.showModal({
							content: res.message || res.msg,
							showCancel: false,
							success: function(res) {
								if (res.confirm) {
									console.log('用户点击确定');
								}
							}
						})
					}
				})
			},
			/**
			 * 成功登录之后给父组件的回调方法
			 */
			successLoginHandler() {
				// this.$emit("successAuth")
			},
		}
	};
</script>

<style lang="less" scoped>
	.wrapper {
		width: 100%;
		.title1{
			margin: 30rpx auto 50rpx auto;
			text-align: center;
		}
		.title2{
			margin-left: 20rpx;
			margin-bottom: 50rpx;
		}
		.btn {
			width: 80%;
			height: auto;
			border: none;
			background-color: #be9364;
			color:#ffffff;
			margin:  0 auto;
			letter-spacing: 0.1em;
			border-radius: 10rpx;
		}
	}
</style>